/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * MainButtonPanel.java
 *
 * Created on Feb 19, 2012, 9:03:27 PM
 */
package dkgg2012group22imat.view;

import dkgg2012group22imat.controller.MainButtonPanelController;
import dkgg2012group22imat.controller.iMatViewController.MainView;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Image;
import javax.imageio.ImageIO;

/**
 *
 * @author jonas
 */
public class MainButtonPanel extends javax.swing.JPanel {

    Image image;
    MainButtonPanelController controller;

    /** Creates new form MainButtonPanel */
    public MainButtonPanel() {
        initComponents();
       
        
        this.controller = new MainButtonPanelController(this);

    }
    
    public void init() {
         //this.setUI(null);
        try {
            image = ImageIO.read(getClass().getResourceAsStream("/dkgg2012group22imat/resources/maintabs_bg.png"));
        } catch (Exception e) {
        }


        //System.out.println(this.getComponentCount());

        //JPanel jPanel4 = jPanel2.clone();


        //System.out.println(this.getSize());


        jLayeredPane1.moveToFront(aboveShadow);
        jLayeredPane1.moveToBack(shadow);
        mainTabCheckoutButton.setShadow(false);
        mainTabShopButton.setShadow(false);
        mainTabEntranceButton.setShadow(true);
        mainTabCheckoutButton.setToolTipText("Gå direkt till kassan");
        mainTabShopButton.setToolTipText("Gå direkt till Butiken");
        mainTabEntranceButton.setToolTipText("Gå direkt till Entrén");
    }

    public void fillSize() {

        shadow.setPreferredSize(new Dimension(this.getWidth(), this.getHeight()));
        shadow.setSize(new Dimension(this.getWidth(), this.getHeight()));
        aboveShadow.setPreferredSize(new Dimension(this.getWidth(), this.getHeight()));
        aboveShadow.setSize(new Dimension(this.getWidth(), this.getHeight()));
        jLayeredPane1.setPreferredSize(new Dimension(this.getWidth(), this.getHeight()));
        jLayeredPane1.setSize(new Dimension(this.getWidth(), this.getHeight()));
    }

    @Override
    protected void paintComponent(Graphics g) {

        this.fillSize();

        this.drawTiled(g);

    }
    /*
     *  Custom painting code for drawing TILED images as the background
     */

    private void drawTiled(Graphics g) {
        Dimension d = getSize();
        int width = image.getWidth(null);
        int height = image.getHeight(null);

        for (int x = 0; x < d.width; x += width) {
            for (int y = 0; y < d.height; y += height) {
                g.drawImage(image, x, y, null, null);
            }
        }
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLayeredPane1 = new javax.swing.JLayeredPane();
        aboveShadow = new javax.swing.JPanel();
        filler1 = new javax.swing.Box.Filler(new java.awt.Dimension(30, 30), new java.awt.Dimension(30, 30), new java.awt.Dimension(30, 30));
        jPanel1 = new javax.swing.JPanel();
        mainTabEntranceButton = new dkgg2012group22imat.view.MainTabButton();
        mainTabShopButton = new dkgg2012group22imat.view.MainTabButton();
        mainTabCheckoutButton = new dkgg2012group22imat.view.MainTabButton();
        shadow = new dkgg2012group22imat.view.MainTabShadow();

        setName("Form"); // NOI18N
        setLayout(new javax.swing.BoxLayout(this, javax.swing.BoxLayout.LINE_AXIS));

        jLayeredPane1.setName("jLayeredPane1"); // NOI18N

        aboveShadow.setName("aboveShadow"); // NOI18N
        aboveShadow.setOpaque(false);
        aboveShadow.setLayout(new java.awt.BorderLayout());

        filler1.setName("filler1"); // NOI18N
        aboveShadow.add(filler1, java.awt.BorderLayout.NORTH);

        jPanel1.setName("jPanel1"); // NOI18N
        jPanel1.setOpaque(false);

        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(dkgg2012group22imat.view.DKGG2012Group22iMatApp.class).getContext().getResourceMap(MainButtonPanel.class);
        mainTabEntranceButton.setBackground(resourceMap.getColor("mainTabEntranceButton.background")); // NOI18N
        mainTabEntranceButton.setIcon(resourceMap.getIcon("mainTabEntranceButton.icon")); // NOI18N
        mainTabEntranceButton.setText(resourceMap.getString("mainTabEntranceButton.text")); // NOI18N
        mainTabEntranceButton.setBorderPainted(false);
        mainTabEntranceButton.setDisabledIcon(resourceMap.getIcon("mainTabEntranceButton.disabledIcon")); // NOI18N
        mainTabEntranceButton.setName("mainTabEntranceButton"); // NOI18N
        mainTabEntranceButton.setPreferredSize(new java.awt.Dimension(190, 80));
        mainTabEntranceButton.setRolloverIcon(resourceMap.getIcon("mainTabEntranceButton.rolloverIcon")); // NOI18N
        mainTabEntranceButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mainTabEntranceButtonActionPerformed(evt);
            }
        });
        jPanel1.add(mainTabEntranceButton);

        mainTabShopButton.setIcon(resourceMap.getIcon("mainTabShopButton.icon")); // NOI18N
        mainTabShopButton.setText(resourceMap.getString("mainTabShopButton.text")); // NOI18N
        mainTabShopButton.setDisabledIcon(resourceMap.getIcon("mainTabShopButton.disabledIcon")); // NOI18N
        mainTabShopButton.setName("mainTabShopButton"); // NOI18N
        mainTabShopButton.setPreferredSize(new java.awt.Dimension(190, 80));
        mainTabShopButton.setRolloverIcon(resourceMap.getIcon("mainTabShopButton.rolloverIcon")); // NOI18N
        mainTabShopButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mainTabShopButtonActionPerformed(evt);
            }
        });
        jPanel1.add(mainTabShopButton);

        mainTabCheckoutButton.setIcon(resourceMap.getIcon("mainTabCheckoutButton.icon")); // NOI18N
        mainTabCheckoutButton.setText(resourceMap.getString("mainTabCheckoutButton.text")); // NOI18N
        mainTabCheckoutButton.setDisabledIcon(resourceMap.getIcon("mainTabCheckoutButton.disabledIcon")); // NOI18N
        mainTabCheckoutButton.setName("mainTabCheckoutButton"); // NOI18N
        mainTabCheckoutButton.setPreferredSize(new java.awt.Dimension(190, 80));
        mainTabCheckoutButton.setRolloverIcon(resourceMap.getIcon("mainTabCheckoutButton.rolloverIcon")); // NOI18N
        mainTabCheckoutButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mainTabCheckoutButtonActionPerformed(evt);
            }
        });
        jPanel1.add(mainTabCheckoutButton);

        aboveShadow.add(jPanel1, java.awt.BorderLayout.CENTER);
        //((FlowLayout)jPanel1.getLayout()).setHgap(20);
        //((FlowLayout)jPanel1.getLayout()).setVgap(20);

        aboveShadow.setBounds(0, 0, 590, 120);
        jLayeredPane1.add(aboveShadow, javax.swing.JLayeredPane.DEFAULT_LAYER);

        shadow.setText(resourceMap.getString("shadow.text")); // NOI18N
        shadow.setName("shadow"); // NOI18N
        shadow.setBounds(0, 0, 110, 16);
        jLayeredPane1.add(shadow, javax.swing.JLayeredPane.DEFAULT_LAYER);

        add(jLayeredPane1);
    }// </editor-fold>//GEN-END:initComponents

private void mainTabEntranceButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mainTabEntranceButtonActionPerformed
    controller.goTo(MainView.ENTRANCE);

}//GEN-LAST:event_mainTabEntranceButtonActionPerformed

private void mainTabShopButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mainTabShopButtonActionPerformed
    controller.goTo(MainView.SHOP);
}//GEN-LAST:event_mainTabShopButtonActionPerformed

private void mainTabCheckoutButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mainTabCheckoutButtonActionPerformed
    controller.goTo(MainView.CHECKOUT);
}//GEN-LAST:event_mainTabCheckoutButtonActionPerformed
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JPanel aboveShadow;
    private javax.swing.Box.Filler filler1;
    private javax.swing.JLayeredPane jLayeredPane1;
    private javax.swing.JPanel jPanel1;
    public dkgg2012group22imat.view.MainTabButton mainTabCheckoutButton;
    public dkgg2012group22imat.view.MainTabButton mainTabEntranceButton;
    public dkgg2012group22imat.view.MainTabButton mainTabShopButton;
    private dkgg2012group22imat.view.MainTabShadow shadow;
    // End of variables declaration//GEN-END:variables
}
